package com.fenghongzhang.day004_rxjava_rxretrofit;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class Main4Activity extends AppCompatActivity {
    private static final String TAG = "Main4Activity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);



        RetrofitUtil.getRetrofitUtil()
                .getRetrofit()
                .create(Api.class)
                .getFood6()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<Food>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(Food food) {
                        Log.i(TAG, "onNext: "+food.getData().size());
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

//
//        test(new Show() {
//            @Override
//            public void print() {
//                System.out.println("哈哈哈哈");
//            }
//        });
//
//        test(() ->{
//            System.out.println("哈哈哈哈");
//        });

//        test2((s) -> {
//            System.out.println(s);
//        });

//        test2(System.out::println);


//            test3((a,b) -> a+b);

//            test3(new Show3() {
//                @Override
//                public int add(int a, int b) {
//                    return a+b;
//                }
//            });


//        List<String> list = Arrays.asList("a", "b", "C", "A", "B");

//        list.sort(new Comparator<String>() {
//            @Override
//            public int compare(String o1, String o2) {
//                return o1.compareToIgnoreCase(o2);
//            }
//        });
//
//        for (String s : list) {
//            System.out.println(s);
//        }




        List<String> list = Arrays.asList("a", "b", "C", "A", "B");
        list.sort((s1,s2)-> s1.compareToIgnoreCase(s2));
        list.forEach(System.out::println);
        list.forEach(s -> {System.out.println(s);});

        list.sort(String::compareToIgnoreCase);
        list.forEach(System.out::println);


    }

    //定义方法,参数是接口
    public void test(Show show){
        show.print();
    }

    //定义方法,参数是接口
    public void test2(Show2 show2){
        show2.print("哈哈");
    }

    //定义方法,参数是接口
    public void test3(Show3 show3){
        int add = show3.add(1, 1);
        System.out.println(add);
    }


}

